{template '_header'}
<div class="page-heading">
    <span class='pull-right'>
        <a class="btn btn-primary">添加商品分组</a>
	</span>
    <h2>添加商品分组</h2>
</div>
<form action="" method="post" class="form-validate form-horizontal ">

    <div class="form-group">
        <label class="col-sm-2 control-label">商品组名称</label>
        <div class="col-sm-9">
            <input type="text" class="form-control valid" name="name" value="{$detail['name']}"
                   data-rule-required="true" placeholder="请输入商品组名称" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">组内商品</label>
        <div class="col-sm-9">
            <div class="form-group" style="height: auto; display: block;">
                <div class="col-sm-12 col-xs-12">
                    <div class="input-group">
                        <input type="text" name="goodsids_text" value="" class="form-control text" readonly="">
                        <div class="input-group-btn">
                            <a class="btn btn-primary" type="button" data-toggle="ajaxModal" href="{php echo webUrl('store.goods.goods',array('page'=>1));}">选择商品</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="goodsarea">
        {loop $goods $k $v}
        <div class="form-group" id="goods{$v['id']}"><label class="col-sm-2 control-label"></label><div class="col-sm-9 col-xs-12"><div class="input-group"><div class="btn form-control">
            {$v['title']}
            <input type="hidden" value="{$v['id']}" name="goodsids[]">
        </div><span class="input-group-addon" style="background-color: #ed5565;color: #fff" onclick="del(this)">X</span></div></div></div>
        {/loop}
    </div>
    <table class='table'>
        <tr>
            <td>
                <input type="submit" class="btn btn-primary" value="保存">
            </td>
        </tr>
        </tbody>
    </table>
</form>

<script language='javascript'>
    $(function () {
        $(':radio[name=type]').click(function () {
            type = $("input[name='type']:checked").val();

            if(type=='1' || type=='3'){
                $('#pick_info').show();
            } else {
                $('#pick_info').hide();
            }
        })
    })

    function clickselect(a) {
        var id = $(a).attr('data-id');
        var type = $(a).attr('data-type');
        var name = $(a).attr('data-name');
        if (type == '1'){
            if ($('#group'+id).length > 0){
                alert('已添加过');
                return;
            }
            var html = '<div class="form-group" id="group'+id+'"><label class="col-sm-2 control-label"></label><div class="col-sm-9 col-xs-12"><div class="input-group"><div class="btn form-control">' +name+
                    '<input type="hidden" value="'+ id +'" name="goodsgroup[]">' +
                    '</div><span class="input-group-addon" style="background-color: #ed5565;color: #fff" onclick="del(this)">X</span></div></div></div>';
        }else{
            if ($('#goods'+id).length > 0){
                alert('已添加过');
                return;
            }
            var html = '<div class="form-group" id="goods'+id+'"><label class="col-sm-2 control-label"></label><div class="col-sm-9 col-xs-12"><div class="input-group"><div class="btn form-control">' +name+
                    '<input type="hidden" value="'+ id +'" name="goodsids[]">' +
                    '</div><span class="input-group-addon" style="background-color: #ed5565;color: #fff" onclick="del(this)">X</span></div></div></div>';
        }
        $('#goodsarea').append(html);
        var goodstext = $('#goodsarea .form-control').text();
        $('input[name="goodsids_text"]').val(goodstext+';');
    }

    function del(a) {
        $(a).parent().parent().parent().remove();
        var goodstext = $('#goodsarea .form-control').text();
        $('input[name="goodsids_text"]').val(goodstext+';');
    }

    function getpagecontent(page,type) {
        url = '{php echo webUrl("store.goods.goods");}&page='+page;
        $.ajax({url:url,type:'get',
            success:function (data) {
                $("#ajaxModal").html('<div class="modal-body"></div>'+data);
            }}
        );
    }
</script>
{template '_footer'}